function createHTTPRequest()
{
    return new XMLHttpRequest();
};


function createHTTPPostRequest (url, multipart)
{
    var xml_HTTP_post = createHTTPRequest();
    xml_HTTP_post.open("POST", url, true);
    if (multipart != true)
	    xml_HTTP_post.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    return xml_HTTP_post;
};


function showAjaxLoad(document_id)
{
    document.getElementById(document_id).innerHTML = "<div class='loader'><img src='/img/loader.gif' /></div>";
};


function runAjax(params)
{
    showAjaxLoad(params.container);
    var ajax_request = (typeof(params.multipart) == "undefined") ? createHTTPPostRequest(params.ruri) : createHTTPPostRequest(params.ruri, params.multipart);

    ajax_request.onreadystatechange = function()
    {
        if (ajax_request.readyState == 4)
        {
            if ((typeof(params.is_controller) == "undefined") || (!params.controller))
            {
                if (typeof(params.on_state_4) == "undefined")
                    document.getElementById(params.container).innerHTML = ajax_request.responseText;
                else
                    params.on_state_4(ajax_request.responseText);

                if ((ajax_request.status == 200) && (typeof(params.on_status_200) != "undefined"))
                    params.on_status_200(ajax_request.responseText);
            }
            else
            {
                var id = params.params.id;

                if (params.params.action == "add")
                    id = getItemID();

                if (((params.params.action == "add") || (params.params.action == "edit") || (params.params.action == "delete")) && (!params.params.no_apply) && (!params.params.no_refresh))
                    expandMenu({controller: "viewbycompany", level: EXPAND_VIEW_BY_COMPANY_COMPANY, parent_id: params.parent_id, id: params.id});
            };
        };
    };

    ajax_request.send(params.args);
};



function openMenu(menu, response)
{
    $("#" + menu).removeClass("closed").addClass("opened");
    $("#" + menu + "_content").show();
    document.getElementById(menu + "_content").innerHTML = response;
};

function closeMenu(menu)
{
    $("#" + menu + "_content").hide();
    $("#" + menu).removeClass("opened").addClass("closed");
};

var EXPAND_VIEW_BY_COMPANY = 1;
var EXPAND_VIEW_BY_COMPANY_IN_COMPANY = 2;
var EXPAND_VIEW_BY_COMPANY_IN_TYPE = 3;
var EXPAND_VIEW_BY_COMPANY_COMPANY = 4;
var EXPAND_VIEW_BY_COMPANY_SPA = 5;

var EXPAND_TYPES = 1;
var EXPAND_TYPES_IN_TYPES = 2;

var EXPAND_ACCOUNTS = 1;
var EXPAND_ACCOUNTS_IN_COMPANY = 2;
var EXPAND_ACCOUNTS_ACCOUNTS = 3;

var EXPAND_SETTINGS = 1;
var EXPAND_SETTINGS_IN_FIRMWARE = 2;
var EXPAND_SETTINGS_FIRMWARE = 3;
var EXPAND_SETTINGS_IN_DICTIONARIES = 4;

var EXPAND_USERS = 1;
var EXPAND_USERS_IN_USERS = 2;



function expandMenu(params)
{
    var ajax_request = createHTTPPostRequest("/menu/" + params.controller);
    var args = "level=" + encodeURIComponent(params.level);

    if (params.id != null)
        args += "&id=" + params.id;

    switch (params.controller)
    {
        case "viewbycompany":
            switch (params.level)
            {
                case EXPAND_VIEW_BY_COMPANY:
                    showAjaxLoad("submenu_view_by_company");
                    ajaxViewByCompany({action: 'index', use_inner: true, no_apply: true});
                    break;

                case EXPAND_VIEW_BY_COMPANY_IN_COMPANY:
                    if ($("#company_" + params.company_id + "_content").is(":visible"))
                    {
                        closeMenu("company_" + params.company_id);
                        return;
                    }
                    else
                        args += "&company_id=" + encodeURIComponent(params.company_id);
                    break;

                case EXPAND_VIEW_BY_COMPANY_IN_TYPE:
                    if ($("#company_" + params.company_id + "_type_" + params.type_id + "_content").is(":visible"))
                    {
                        closeMenu("company_" + params.company_id + "_type_" + params.type_id);
                        return;
                    }
                    else
                        args += "&company_id=" + encodeURIComponent(params.company_id) + "&type_id=" + encodeURIComponent(params.type_id);
                    break;


                case EXPAND_VIEW_BY_COMPANY_SPA:
                    args += "&type_id=" + encodeURIComponent(params.type_id) + "&company_id=" + encodeURIComponent(params.company_id);
                    showAjaxLoad("submenu_view_by_company");
                    break;

                case EXPAND_VIEW_BY_COMPANY_COMPANY:
                    args += "&parent_id=" + encodeURIComponent(params.parent_id);
                    showAjaxLoad("submenu_view_by_company");
                    break;
            }
            break;


        case "types":
            switch (params.level)
            {
                case EXPAND_TYPES:
                    showAjaxLoad("submenu_types");
                    ajaxTypes({id: 0, action: 'index', use_inner: true, no_apply: true});
                    break;

                case EXPAND_TYPES_IN_TYPES:
                    showAjaxLoad("submenu_types");
                    break;
            };
            break;


        case "accounts":
            switch (params.level)
            {
                case EXPAND_ACCOUNTS:
                    showAjaxLoad("submenu_accounts");
                    ajaxAccounts({action: 'index', use_inner: true, no_apply: true});
                    break;

                case EXPAND_ACCOUNTS_ACCOUNTS:
                    args += "&company_id=" + encodeURIComponent(params.company_id);
                    showAjaxLoad("submenu_accounts");
                    break;

                case EXPAND_ACCOUNTS_IN_COMPANY:
                    if ($("#accounts_company_" + params.company_id + "_content").is(":visible"))
                    {
                        closeMenu("accounts_company_" + params.company_id);
                        return;
                    }
                    else
                        args += "&company_id=" + encodeURIComponent(params.company_id);
                    break;
            }
            break;


        case "settings":
            switch (params.level)
            {
                case EXPAND_SETTINGS:
                    showAjaxLoad("submenu_settings");
                    ajaxSettings({id: 0, action: 'index', use_inner: true, no_apply: true});
                    break;

                case EXPAND_SETTINGS_IN_FIRMWARE:
                    if ($("#settings_4_content").is(":visible"))
                    {
                        closeMenu("settings_4");
                        return;
                    };
                    break;

                case EXPAND_SETTINGS_FIRMWARE:
                    showAjaxLoad("submenu_settings");
                    break;

                case EXPAND_SETTINGS_IN_DICTIONARIES:
                    if ($("#settings_5_content").is(":visible"))
                    {
                        closeMenu("settings_5");
                        return;
                    };

                    break;
            };
            break;

        case "users":
            switch (params.level)
            {
                case EXPAND_USERS:
                    showAjaxLoad("submenu_users");
                    ajaxUsers({id: 0, action: 'index', use_inner: true, no_apply: true});
                    break;

                case EXPAND_USERS_IN_USERS:
                    showAjaxLoad("submenu_users");
                    break;
            };
            break;
    };


    ajax_request.onreadystatechange = function()
    {
        if (ajax_request.readyState == 4)
        {
            if (ajax_request.status == 200)
            {
                switch (params.controller)
                {
                    case "viewbycompany":
                        switch (params.level)
                        {
                            case EXPAND_VIEW_BY_COMPANY:
                                document.getElementById('submenu_view_by_company').innerHTML = ajax_request.responseText;
                                break;

                            case EXPAND_VIEW_BY_COMPANY_IN_COMPANY:
                                openMenu("company_" + params.company_id, ajax_request.responseText);
                                break;

                            case EXPAND_VIEW_BY_COMPANY_IN_TYPE:
                                openMenu("company_" + params.company_id + "_type_" + params.type_id, ajax_request.responseText);
                                break;


                            case EXPAND_VIEW_BY_COMPANY_COMPANY:
                            case EXPAND_VIEW_BY_COMPANY_SPA:
                                document.getElementById('submenu_view_by_company').innerHTML = ajax_request.responseText;
                                break;
                        };
                        break;


                    case "types":
                        switch (params.level)
                        {
                            case EXPAND_TYPES:
                            case EXPAND_TYPES_IN_TYPES:
                                document.getElementById('submenu_types').innerHTML = ajax_request.responseText;
                                break;
                        };
                        break;


                    case "accounts":
                        switch (params.level)
                        {
                            case EXPAND_ACCOUNTS:
                            case EXPAND_ACCOUNTS_ACCOUNTS:
                                document.getElementById('submenu_accounts').innerHTML = ajax_request.responseText;
                                break;

                            case EXPAND_ACCOUNTS_IN_COMPANY:
                                openMenu("accounts_company_" + params.company_id, ajax_request.responseText);
                                break;
                        }
                        break;


                    case "settings":
                        switch (params.level)
                        {
                            case EXPAND_SETTINGS:
                                document.getElementById('submenu_settings').innerHTML = ajax_request.responseText;
                                break;

                            case EXPAND_SETTINGS_IN_FIRMWARE:
                                openMenu("settings_4", ajax_request.responseText);
                                break;

                            case EXPAND_SETTINGS_FIRMWARE:
                                document.getElementById('submenu_settings').innerHTML = ajax_request.responseText;
                                break;

                            case EXPAND_SETTINGS_IN_DICTIONARIES:
                                openMenu("settings_5", ajax_request.responseText);
                                break;
                        };
                        break;

                    case "users":
                        switch (params.level)
                        {
                            case EXPAND_USERS:
                            case EXPAND_USERS_IN_USERS:
                                document.getElementById('submenu_users').innerHTML = ajax_request.responseText;
                                break;
                        };
                        break;
                };
            }
            else
                alert('There was a problem with the request.');
        };
    };

    ajax_request.send(args);
};


function ajaxSpa(params)
{
    var args = "id=" + params.id;

    if (!params.no_apply)
    {
        switch(params.action)
        {
            case "edit":
            case "add":
                ip = encodeURIComponent(document.getElementById('spa_ip').value);
                mac = encodeURIComponent(document.getElementById('spa_mac').value);
                serial = encodeURIComponent(document.getElementById('spa_serial').value);
                args += "&ip=" + ip + "&mac=" + mac + "&serial=" + serial + "&company_id=" + params.company_id + "&type_id=" + params.type_id;
                for (i = 0; i < params.ext_count; i++)
                    args += "&ext" + i + "=" + encodeURIComponent(document.getElementById('spa_ext_' + i).value);
            break;

            case "customize":
                for (var i = 0; i <= params.templates_count + 1; i++)
                    args += "&ext" + i + "_template=" + encodeURIComponent(document.getElementById("ext" + i + "_template").value);
                args += "&count=" + params.templates_count;
            break;

            case "delete":
            break;
        };

        args += "&apply=1";
    };

    runAjax({
        container: (params.use_inner ? "inner" : "container"),
        ruri: "/spa/" + params.action,
        args: args,
        on_status_200: function() {
            if (params.action == "add")
                params.id = getItemID();

            if (((params.action == "add") || (params.action == "edit") || (params.action == "delete")) && (!params.no_apply) && (!params.no_refresh))
                expandMenu({controller: "viewbycompany", level: EXPAND_VIEW_BY_COMPANY_SPA, company_id: params.company_id, type_id: params.type_id, id: params.id});
        }
    });
};


function ajaxViewByCompany(params)
{
    var args = "id=" + params.id;

    if (!params.no_apply)
    {
        switch (params.action)
        {
            case "edit":
            case "add":
                var caption = encodeURIComponent(document.getElementById('caption').value);
                var company_type = encodeURIComponent(document.getElementById('company_type').value);
                var proxy = encodeURIComponent(document.getElementById('proxy').value);
                var vlan = encodeURIComponent(document.getElementById('vlan').value);
                var vlan_pc = encodeURIComponent(document.getElementById('vlan_pc').value);
                args += "&company_type=" + company_type + "&caption=" + caption + "&vlan=" + vlan + "&vlan_pc=" + vlan_pc + "&proxy=" + proxy;

                switch (parseInt(company_type))
                {
                    case 1: // Company
                    case 2: // Pool
                        ip = encodeURIComponent(document.getElementById('ip').value);
                        args += "&ip=" + ip;
                    break;

                    case 3: // Company in an existing pool
                        params.parent_id = document.getElementById('pool').value;
                        args += "&pool_id=" + encodeURIComponent(params.parent_id);
                    break;

                    default:
                        alert("Problem in script!");
                        return;
                };
            break;

            case "customize":
                global_template = encodeURIComponent(document.getElementById('global_template').value);
                ext_template = encodeURIComponent(document.getElementById('ext_template').value);

                args += "&global_template=" + global_template + "&ext_template=" + ext_template;
            break;
        };

        args += "&apply=1";
    };

    runAjax({
        container: (params.use_inner ? "inner" : "container"),
        ruri: "/viewbycompany/" + params.action,
        args: args,
        on_status_200: function() {
            if (params.action == "add")
                params.id = getItemID();

            if (((params.action == "add") || (params.action == "edit") || (params.action == "delete")) && (!params.no_apply) && (!params.no_refresh))
                expandMenu({controller: "viewbycompany", level: EXPAND_VIEW_BY_COMPANY_COMPANY, parent_id: params.parent_id, id: params.id});
        }
    });
};


function ajaxTypes(params)
{
    var args = "id=" + params.id;

    if (params.company_id)
    		args += "&company_id=" + encodeURIComponent(params.company_id);

    if (!params.no_apply)
    {
        switch (params.action)
        {
            case "add":
                var exts = encodeURIComponent(document.getElementById("exts").value);
                args += "&exts=" + exts;
            case "edit":
                var tftp_filename = encodeURIComponent(document.getElementById("tftp_filename").value);
                var caption = encodeURIComponent(document.getElementById("caption").value);
                var firmware_id = encodeURIComponent(document.getElementById("firmware_id").value);
                args += "&tftp_filename=" + tftp_filename + "&caption=" + caption + "&firmware_id=" + firmware_id;

            break;

            case "tftp":
                var tftp_use_default_config = "";
                var tftp_add_extra_config = "";

                if (!$("#tftp_use_default_config").attr("checked"))
                {
                    tftp_use_default_config = "1";
                    var tftp_custom_config = encodeURIComponent(document.getElementById("tftp_custom_config").value);
                    args += "&tftp_custom_config=" + tftp_custom_config;
                }
                else
                    tftp_use_default_config = "2";

                if (!$("#tftp_add_extra_config").attr("checked"))
                    tftp_add_extra_config = "1";
                else
                {
                    var tftp_extra_config = encodeURIComponent(document.getElementById("tftp_extra_config").value);
                    args += "&tftp_extra_config=" + tftp_extra_config;
                    tftp_add_extra_config = "2";
                };


                args += "&tftp_use_default_config=" + tftp_use_default_config + "&tftp_add_extra_config=" + tftp_add_extra_config;
            break;

            case "customize":
            case "short":
                for (i = 0; i <= params.exts_count + 1; i++)
                    args += "&ext" + i + "_template=" + encodeURIComponent(document.getElementById("ext" + i + "_template").value);
            break;
        };

        args += "&apply=1";
    };

    runAjax({
        container: (params.use_inner ? "inner" : "container"),
        ruri: "/types/" + params.action,
        args: args,
        on_status_200: function() {
            if (params.action == "add")
                params.id = getItemID();

            if (((params.action == "add") || (params.action == "edit") || (params.action == "delete")) && (!params.no_apply) && (!params.no_refresh))
                expandMenu({controller: "types", level: EXPAND_TYPES_IN_TYPES, id: params.id});
        }
    });
};


function ajaxAccounts(params)
{
    var args = "id=" + encodeURIComponent(params.id);
    
    if (!params.no_apply)
    {
        switch (params.action)
        {
            case "edit":
            case "add":
                account_login = encodeURIComponent(document.getElementById('account_login').value);
                account_password = encodeURIComponent(document.getElementById('account_password').value);
                account_display_name = encodeURIComponent(document.getElementById('account_display_name').value);
                account_short_name = encodeURIComponent(document.getElementById('account_short_name').value);

                args += "&login=" + account_login + "&password=" + account_password + "&display_name=" + account_display_name +
                    "&short_name=" + account_short_name + "&company_id=" + encodeURIComponent(params.company_id);
                break;

            case "delete":
                break;
        };
        
        args += "&apply=1";
    };

    runAjax({
        container: (params.use_inner ? "inner" : "container"),
        ruri: "/accounts/" + params.action,
        args: args,
        on_status_200: function() {
            if (params.action == "add")
                params.id = getItemID();

            if (((params.action == "add") || (params.action == "edit") || (params.action == "delete")) && (!params.no_apply) && (!params.no_refresh))
                expandMenu({controller: "accounts", level: EXPAND_ACCOUNTS_ACCOUNTS, company_id: params.company_id, id: params.id});
        }
    });
};


function ajaxSettings(params)
{
	var args = "id=" + params.id;

    if (!params.no_apply)
    {

		switch(params.id)
		{
			case 1: // Default profile
				var template_global = encodeURIComponent(document.getElementById("template_global").value);
				var template_ext = encodeURIComponent(document.getElementById("template_ext").value);
				args += "&template_global=" + template_global + "&template_ext=" + template_ext;
			    break;

            case 2: // DNS
                var dns_primary = encodeURIComponent(document.getElementById("dns_primary").value);
                var dns_secondary = encodeURIComponent(document.getElementById("dns_secondary").value);
                var dns_server_order = encodeURIComponent(document.getElementById("dns_server_order").value);
                var dns_query_mode = encodeURIComponent(document.getElementById("dns_query_mode").value);

                args += "&dns_primary=" + dns_primary + "&dns_secondary=" + dns_secondary +
                    "&dns_server_order=" + dns_server_order + "&dns_query_mode=" + dns_query_mode;
                break;

            case 6: // TFTP
                var tftp_path_to_initial_configs = encodeURIComponent(document.getElementById("tftp_path_to_initial_configs").value);
                var tftp_default_config = encodeURIComponent(document.getElementById("tftp_default_config").value);
                args += "&tftp_path_to_initial_configs=" + tftp_path_to_initial_configs + "&tftp_default_config=" + tftp_default_config;
                break;

            case 7: // DHCP
                var dhcp_restart_command = encodeURIComponent(document.getElementById("dhcp_restart_command").value);
                var dhcp_config_file = encodeURIComponent(document.getElementById("dhcp_config_file").value);
                args += "&dhcp_restart_command=" + dhcp_restart_command + "&dhcp_config_file=" + dhcp_config_file;
                break;

            case 8: // Common
                var hostname = encodeURIComponent(document.getElementById("hostname").value);
                var resync_periodic = encodeURIComponent(document.getElementById("resync_periodic").value);
                args += "&hostname=" + hostname + "&resync_periodic=" + resync_periodic;
                break;

            case 9: // Web access
                var web_server_enable = "";
                if ($("#web_server_enable").attr("checked"))
                {
                    web_server_enable = 2;
                    args += "&web_server_port=" + encodeURIComponent(document.getElementById("web_server_port").value);

                    var web_admin_access_enable = "";
                    if ($("#web_admin_access_enable").attr("checked"))
                    {
                        web_admin_access_enable = 2;
                        args += "&web_admin_password=" + encodeURIComponent(document.getElementById("web_admin_password").value);
                    }
                    else
                        web_admin_access_enable = 1;

                    args += "&web_admin_access_enable=" + web_admin_access_enable;
                }
                else
                    web_server_enable = 1;

                args += "&web_server_enable=" + web_server_enable;
                break;
        };

        args += "&apply=1";
	};

    runAjax({
        container: (params.use_inner ? "inner" : "container"),
        ruri: "/settings/" + params.action,
        args: args
    });
};


function ajaxFirmwares(params)
{
    var args = "";
	if (params.id)
		args += "&id=" + encodeURIComponent(params.id);

    if (!params.no_apply)
    {
        switch(params.action)
        {
            case "index":
                args += "&upgrade_error_retry_delay=" + encodeURIComponent(document.getElementById('upgrade_error_retry_delay').value);
                break;

            case "delete":
                break;

            case "add":
                var file = document.getElementById("file").files[0];
                var fd = new FormData();
                fd.append("apply", "1");
                fd.append("caption", encodeURIComponent(document.getElementById('caption').value));
                fd.append("version", encodeURIComponent(document.getElementById('version').value));
                fd.append("firmware", file);
                break;

            case "edit":
                args += "&caption=" + encodeURIComponent(document.getElementById('caption').value) +
                        "&version=" + encodeURIComponent(document.getElementById('version').value);
            break;
        };

        args += "&apply=1";
    };

    runAjax({
        container: (params.use_inner ? "inner" : "container"),
        ruri: "/firmwares/" + params.action,
        multipart: ((!params.no_apply) && (params.action == "add")),
        args: (((!params.no_apply) && (params.action == "add")) ? fd : args),
        on_status_200: function() {
            if (params.action == "add")
                params.id = getItemID();

            if (((params.action == "add") || (params.action == "edit") || (params.action == "delete")) && (!params.no_apply) && (!params.no_refresh))
                expandMenu({controller: "settings", level: EXPAND_SETTINGS_FIRMWARE, id: params.id});
        }
    });
};


function ajaxDictionaries(params)
{
	var ajax_request = createHTTPPostRequest("/dictionaries/" + params.action);
    var args = "";
	if (params.id)
		args += "&id=" + encodeURIComponent(params.id);

    if (!params.no_apply)
    {
        /*
        switch(params.action)
        {
            case "index":
                args += "&upgrade_error_retry_delay=" + encodeURIComponent(document.getElementById('upgrade_error_retry_delay').value);
                break;

            case "delete":
                break;

            case "add":
            case "edit":
                args += "&caption=" + encodeURIComponent(document.getElementById('caption').value) +
                        "&version=" + encodeURIComponent(document.getElementById('version').value);
            break;
        };

        args += "&apply=1";
        */
    };


    showAjaxLoad(params.container);

	ajax_request.onreadystatechange = function()
	{
		if (ajax_request.readyState == 4)
	    {
            document.getElementById(params.container).innerHTML = ajax_request.responseText;

			if (ajax_request.status == 200)
			{
                /*
                if (((params.action == "add") || (params.action == "edit") || (params.action == "delete")) && (!params.no_apply) && (!params.no_refresh))
                    expandMenu({controller: "settings", level: EXPAND_SETTINGS_FIRMWARE});
                */
			};
		};
	};

	ajax_request.send(args);
};


function ajaxUsers(params)
{
    var args = "id=" + encodeURIComponent(params.id);

    if (!params.no_apply)
    {
        switch (params.action)
        {
            case "edit":
                args += "&login=" + encodeURIComponent(document.getElementById("login").value)
                    + "&password=" + encodeURIComponent(document.getElementById("password").value)
                    + "&name=" + encodeURIComponent(document.getElementById("name").value)
                    + "&last_name=" + encodeURIComponent(document.getElementById("last_name").value)
                    + "&role=" + encodeURIComponent(document.getElementById("role").value);
                break;
            case "add":
                args += "&login=" + encodeURIComponent(document.getElementById("login").value)
                    + "&password=" + encodeURIComponent(document.getElementById("password").value)
                    + "&name=" + encodeURIComponent(document.getElementById("name").value)
                    + "&last_name=" + encodeURIComponent(document.getElementById("last_name").value)
                    + "&role=" + encodeURIComponent(document.getElementById("role").value);
                break;
            case "delete":
                break;
        };

        args += "&apply=1";
    };

    runAjax({
        container: (params.use_inner ? "inner" : "container"),
        ruri: "/user/" + params.action,
        args: args,
        on_status_200: function()
        {
            if (((params.action == "add") || (params.action == "edit") || (params.action == "delete")) && (!params.no_apply) && (!params.no_refresh))
                expandMenu({controller: "users", level: EXPAND_USERS_IN_USERS, id: params.id});
        }
    });
}


function addItem(params)
{
    var args = "";
    var ajax_request = createHTTPPostRequest( (params.menu == "device" ? "spa/adddevice" : (params.menu + "/add") ));

    showAjaxLoad(params.container);

    switch (params.menu)
    {
        case "device":
            args += "company_id=" + params.company_id;
            break;

        case "spa":
            args += "company_id=" + params.company_id + "&type_id=" + params.type_id;
            break;

        case "accounts":
            args += "company_id=" + params.company_id;
            break;

        case "viewbycompany":
            if (params.pool_id)
                args += "&pool_id=" + params.pool_id;
            break;
    };

    ajax_request.onreadystatechange = function()
    {
        if (ajax_request.readyState == 4)
            document.getElementById(params.container).innerHTML = ajax_request.responseText;
    };

    ajax_request.send(args);
};


function doSearch(search_text, search_table, container)
{
	text = encodeURIComponent(search_text);
	table = encodeURIComponent(search_table);
	args = "search_text=" + text + "&search_table=" + table;

    runAjax({
        container: container,
        ruri: "/search/index",
        args: args,
        on_state_4: function(response_text) {
            $("#search_results").slideDown();
            document.getElementById(container).innerHTML = response_text;
        }
    });
};


function getItemID() { return parseInt(document.getElementById("item_id").value); };
function getReloadFlag() { return (parseInt(document.getElementById("reload_flag").value) == 1); };